package dhm.com.dhmshop.updata.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.mine.SaleHistoryAdapter;
import dhm.com.dhmshop.base.BaseActiity;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.SaleDetailBean;
import dhm.com.dhmshop.utils.SpUtils;

public class SalehistoryActivity extends BaseActiity implements LoginContract.IView {

    String id;
    @BindView(R.id.recy_data)
    RecyclerView recyData;
    private PressenterImpl pressenter;
    private SaleHistoryAdapter saleHistoryAdapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_salehistory;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        id = getIntent().getStringExtra("id");
        pressenter = new PressenterImpl();
        pressenter.attachView(this);
        String uid = SpUtils.getString(this, "uid");
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        saleHistoryAdapter = new SaleHistoryAdapter(this);
        recyData.setAdapter(saleHistoryAdapter);
        recyData.setLayoutManager(manager);
        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("uid", uid);
        map.put("id", id);
        pressenter.sendMessage(this, Constant.ServiceDetail, map, SaleDetailBean.class);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void requesta(Object data) {
        if (data instanceof SaleDetailBean) {
            SaleDetailBean saleDetailBean = (SaleDetailBean) data;
            if (saleDetailBean.getCode() == 1) {
                saleHistoryAdapter.setShopList(saleDetailBean.getData().getLog());
            }
        }

    }

    @Override
    public void fail(String error) {

    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
